#!/bin/bash -x
######################################
#                                    #
# prepare tar.bz2 from source        #
# currently for nemecp4 branch only  # 
# Pavel Nemec <nemecp4 gmail com>    #
# GPL v2 or later                    #
#                                    # 
######################################

VERSION=$(cat version)
SOURCE="nemecp4"
TARGET="kabsa-${VERSION}.tar.bz2"
TMP="/tmp/"
TMPTARGET="${TMP}kabsa-${VERSION}"

if [ -d "${TMPTARGET}" ]
then
  echo "dir $TMPTARGET"
  rm -rf "${TMPTARGET}"
fi
install -d "${TMPTARGET}" 

#
# copy and clean
cp -ar ${SOURCE}/* $TMPTARGET/ 
find "${TMPTARGET}" -name ".svn" -exec rm -rf {} \+
find "${TMPTARGET}" -name "*.pyc" -exec rm -rf {} \+
find "${TMPTARGET}" -name "*~" -exec rm -rf {} \+

tar -cjf $TARGET -C ${TMP} "kabsa-${VERSION}/"

if [ $? -eq 0 ]
then
  echo "printing result:"
  tar -tf ${TARGET}
else
  echo "packing failed" 
fi